package com.xinqi.modules.prepare.question.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareQuestionBankData;
import com.xinqi.modules.prepare.question.domain.PrepareQuestionBankEntity;
import com.xinqi.common.base.dto.QuestionBaseDTO;
import com.xinqi.modules.prepare.question.dto.req.PrepareQuestionBankCreateDTO;
import com.xinqi.modules.prepare.question.dto.req.PrepareQuestionBankUpdateDTO;
import com.xinqi.modules.prepare.question.dto.rsp.PrepareQuestionBankResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区测评卷试题表转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareQuestionBankConvert {
    @Mapping(source = "type", target = "questionType")
    @Mapping(target = "optionList", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getOptionList()))")
    @Mapping(target = "questionFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionFiles()))")
    @Mapping(target = "answerFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getAnswerFiles()))")
    @Mapping(target = "analysisFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getAnalysisFiles()))")
    public abstract PrepareQuestionBankEntity create(PrepareQuestionBankCreateDTO s);

    public abstract PrepareQuestionBankCreateDTO create(PrepareQuestionBankData s);

    @Mapping(source = "type", target = "questionType")
    @Mapping(target = "optionList", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getOptionList()))")
    @Mapping(target = "questionFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionFiles()))")
    @Mapping(target = "answerFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getAnswerFiles()))")
    @Mapping(target = "analysisFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getAnalysisFiles()))")
    public abstract PrepareQuestionBankEntity update(PrepareQuestionBankUpdateDTO s, @MappingTarget PrepareQuestionBankEntity t);

    @Mapping(source = "type", target = "questionType")
    @Mapping(target = "optionList", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getOptionList()))")
    @Mapping(target = "questionFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionFiles()))")
    @Mapping(target = "answerFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getAnswerFiles()))")
    @Mapping(target = "analysisFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getAnalysisFiles()))")
    public abstract PrepareQuestionBankEntity update(PrepareQuestionBankUpdateDTO s);

    @Mapping(source = "questionType", target = "type")
    @Mapping(target = "optionList", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getOptionList(), com.xinqi.common.base.dto.QuestionOptionsDTO.class))")
    @Mapping(target = "questionFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getQuestionFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    @Mapping(target = "answerFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getAnswerFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    @Mapping(target = "analysisFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getAnalysisFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract PrepareQuestionBankResultDTO convert(PrepareQuestionBankEntity s);

    public abstract PrepareQuestionBankData convert(PrepareQuestionBankResultDTO s);


    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareQuestionBankEntity copy(PrepareQuestionBankEntity sources, @MappingTarget PrepareQuestionBankEntity prepareQuestionBankEntity);

    @Mapping(source = "questionType", target = "type")
    @Mapping(target = "optionList", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getOptionList(), com.xinqi.common.base.dto.QuestionOptionsDTO.class))")
    @Mapping(target = "questionFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getQuestionFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    @Mapping(target = "answerFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getAnswerFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    @Mapping(target = "analysisFiles", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getAnalysisFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract QuestionBaseDTO entity2Base(PrepareQuestionBankEntity s);
}
